Hi Sam,
KFLOP only has one processor (although there are 8 functional units that can potentially perform 8 instructions every 5ns CPU cycle). The User threads are time-sliced in a manner that guarantees CPU time for each User Thread regardless of what the Thread is doing. The Servo Interrupt that performs Trajectory, Servo Feedback, Limits, IO management, etc. has top
priority and always executes and completes every 90us regardless of how many other Threads are active or what they are doing. See here for more info:
However there may be another reason for not performing a tight loop like in your example. Such a loop may be preempted by a time slice partially through an operation such as ReadBit or EnableAxis or DisableAxis. If other Threads happen to perform certain operations for example Jog() with a partially disabled axis the results may be unpredictable.
Also there is no
significant advantage in having a tight loop as there will be basically the same worst case response of one time slice anyway.
So we recommend adding a WaitNextTimeSlice() in the loop to perform any operation once per time slice in an uninterrupted manner.
Regarding the pseudo code: it also isn't a good idea to continuously enable/disable the axes if they are already enabled/disabled. It also may not make sense to necessarily enable all the axis when "abort" is removed. Usually a complete re-initialization is required (maybe that is what your pseudo code implied).
Thread #0 is the KFLOP System Thread and not available for your use.
So consider something like:
#include "KMotionDef.h"
#define AbortBit 152
main()
{
for (;;) //loop forever
{
WaitNextTimeSlice();
// if any axes channels are enabled and the
// Abort signal is active then disable all
if (((ch0->Enable || ch1->Enable || ch2->Enable) && ReadBit(AbortBit)))
{
DisableAxis(0);
DisableAxis(1);
DisableAxis(2);
}
}
}
HTH
Regards
TK
From: "Sam Marrocco SMarrocco@... [DynoMotion]" <DynoMotion@yahoogroups.com>
To: "DynoMotion@yahoogroups.com" <DynoMotion@yahoogroups.com>
Sent: Thursday, July 31, 2014 6:27 PM
Subject: [DynoMotion] Hardware abort options....
I'm attempting to add a true hardware abort button to the KFlop.
I have a button/pull down resistor setup on IO Pin 0 from which I can read the state. My intention is download a short piece of C code that basically loops forever watching the state of that pin, then disabling/reenabling the Axis as required.
Knowing that code runs very fast in the hardware and that I want to read the button's state as quickly as possible I'm thinking the loop should be as fast as possible---quite literally (pseudocode)
<running in Thread 0>
while(TRUE)
{
If CheckBit(AbortBit)==TRUE
DisableAllAxes;
else
ReEnableAllAxes;
}
Is there any reason that I should include a short pause in the loop--I'm concerned that I might "steal too many cycles" from the KFlop--or is that irrelevant because the thread running my code is on it's own "processor" and independent of the KFlop's other
activities? Or is this the purpose of the WaitNextTimeSlice() function? Obviously I wouldn't want anything such as bad code in another thread preventing an abort from being detected in this manner.
sam marrocco | chief technical officer
ringside.cutters.picnic.moonlink
248 548 2500 w
248 910 3344 c
ringsidecreative.com